package pervasivePositioning.pos;
import android.R.bool;
import android.location.Location;
import android.util.Log;

public class AccelerationStrategy extends ReportingStrategy {
	
	private float threshold = 0;
	private boolean inMotion = false;
	private float last[] = {0,0,0};
	
	public AccelerationStrategy() {
	}
	
	public void setValue(float t) {
		if (threshold >= 0) {
			threshold = t;
		}
	}
	
	@Override
	public float getValue() {
		return threshold;		
	}

	public boolean reportAcceleration(float[] values) {
		inMotion = true;
		
		Log.e("pp", String.format("(%f,%f,%f)%n", Math.abs(last[0] - values[0]), Math.abs(last[1] - values[1]), Math.abs(last[2] - values[2])));
		if (Math.abs(last[0] - values[0]) < threshold
			&& Math.abs(last[1] - values[1]) < threshold
			&& Math.abs(last[2] - values[2]) < threshold) {
			
			inMotion = false;
		}
		if(inMotion)
			last = values;
		return inMotion;
	}

	public boolean reportPosition(Location newloc) {
		Log.e("pp", String.format("InMotion: %b%n", inMotion));
		return inMotion;
	}
	
	
	@Override
	public String getName() {
		return "AccelerationStrategy";
	}

	@Override
	public String getValueName() {
		return "threshold";
	}	
	
	@Override
	public String getConfig() {
		// TODO Auto-generated method stub
		return String.valueOf(threshold);
	}
}
